/*
 * [Ronny Abraham]
 * [ronnya@gmail.com]
 * CS530:DUI, Assignment [#1]
 */

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Polygon;

/*
 * ActorGeometry
 * defines the geometry of an actor
 */

public class ActorGeometry
{
	/*
	 * construct a default actor
	 */
	public ActorGeometry()
	{
		// shirt
		int shirtXArr[] = {75, 75, 50, 50, 150, 150, 125, 125};
		int shirtYArr[] = {115, 145, 145, 165, 165, 145, 145, 115};
		shirt = new Polygon(shirtXArr, shirtYArr, 8);
		//pants
		int pantsXArr[] = {55, 75, 125, 145, 115, 100, 85};
		int pantsYArr[] = {75, 115, 115, 75, 75, 105, 75};
		pants = new Polygon(pantsXArr, pantsYArr, 7);
		// head
		headPosition = new Point(75, 215);
		headWidth = 50;
		headHeight = 50;
		// eyes
		eyeR = new Point(90, 200);
		eyeL = new Point(105, 200);
		eyeWidth = eyeHeight = 5;
		
		socketR = new Point(87, 202);
		socketL = new Point(102, 202);
		socketWidth = socketHeight = 10;
		// mouth
		mouthPos = new Point(80, 215);
		mouthWidth = 40;
		mouthHeight = 40;
		startAngle = 225;
		arcAngle = 90;
		mouthNeutralR = new Point(90, 180);
		mouthNeutralL = new Point(110, 180);
	}
	
	/*
	 * worldToPanel
	 * converts world coordinates to panel coordinates
	 */
	public void worldToPanel()
	{
		WorldToPanelCoordinates converter = new WorldToPanelCoordinates(panelDimension);
		converter.worldToPanel(shirt);
		converter.worldToPanel(pants);
		converter.worldToPanel(headPosition);
		converter.worldToPanel(eyeR);
		converter.worldToPanel(eyeL);
		converter.worldToPanel(socketR);
		converter.worldToPanel(socketL);
		converter.worldToPanel(mouthPos);
		converter.worldToPanel(mouthNeutralR);
		converter.worldToPanel(mouthNeutralL);
	}
	
	
	public void translate(int x, int y)
	{
		for(int i = 0; i < shirt.npoints; ++i)
		{
			shirt.xpoints[i] += x;
			shirt.ypoints[i] += y;
		}
		
		for(int i = 0; i < pants.npoints; ++i)
		{
			pants.xpoints[i] += x;
			pants.ypoints[i] += y;
		}
		
		headPosition.x += x;
		headPosition.y += y;
		eyeR.x += x;
		eyeR.y += y;
		eyeL.x += x;
		eyeL.y += y;
		socketR.x += x;
		socketR.y += y;
		socketL.x += x;
		socketL.y += y;
		mouthPos.x += x;
		mouthPos.y += y;
		mouthNeutralR.x += x;
		mouthNeutralR.y += y;
		mouthNeutralL.x += x;
		mouthNeutralL.y += y;
	}
	
	public void scale(float sX, float sY)
	{
		// location of points
		for(int i = 0; i < shirt.npoints; ++i)
		{
			shirt.xpoints[i] = Math.round(shirt.xpoints[i] * sX);
			shirt.ypoints[i] = Math.round(shirt.ypoints[i] * sY);
		}
		
		for(int i = 0; i < pants.npoints; ++i)
		{
			pants.xpoints[i] = Math.round(pants.xpoints[i] * sX);
			pants.ypoints[i] = Math.round(pants.ypoints[i] * sY);
		}
		
		headPosition.x = Math.round(headPosition.x * sX);
		headPosition.y = Math.round(headPosition.y * sY);
		eyeR.x = Math.round(eyeR.x * sX);
		eyeR.y = Math.round(eyeR.y * sY);
		eyeL.x = Math.round(eyeL.x * sX);
		eyeL.y = Math.round(eyeL.y * sY);
		socketR.x = Math.round(socketR.x * sX);
		socketR.y = Math.round(socketR.y * sY);
		socketL.x = Math.round(socketL.x * sX);
		socketL.y = Math.round(socketL.y * sY);
		mouthPos.x = Math.round(mouthPos.x * sX);
		mouthPos.y = Math.round(mouthPos.y * sY);
		// scale size of head, eyes and mouth
		headWidth = Math.round(headWidth * sX);
		headHeight = Math.round(headHeight * sY);
		eyeWidth = Math.round(eyeWidth * sX);
		eyeHeight = Math.round(eyeHeight * sY);
		socketWidth = Math.round(socketWidth * sX);
		socketHeight = Math.round(socketHeight * sY);
		mouthWidth = Math.round(mouthWidth * sX);
		mouthHeight = Math.round(mouthHeight * sY);
		mouthNeutralR.x = Math.round(mouthNeutralR.x * sX);
		mouthNeutralR.y = Math.round(mouthNeutralR.y * sY);
		mouthNeutralL.x = Math.round(mouthNeutralL.x * sX);
		mouthNeutralL.y = Math.round(mouthNeutralL.y * sY);
	}
	
	public static Dimension panelDimension = new Dimension(200, 300);
	public Polygon shirt, pants;
	public Point headPosition, eyeR, eyeL, socketR, socketL, mouthPos, mouthNeutralR, mouthNeutralL;
	public int headWidth, headHeight, eyeWidth, eyeHeight, socketWidth, socketHeight, mouthWidth, mouthHeight, startAngle, arcAngle;
	
}
